package com.jt.serviceImpl;

import com.jt.pojo.SearchResult;
import com.jt.service.ItemCatService;
import com.jt.util.HttpClientService;
import com.jt.utils.ObjectMapperUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @author dc
 * @Classname ItemCatServiceImpl
 * @Date 2020/5/6 10:29
 */
@Service
public class ItemCatServiceImpl implements ItemCatService {

    @Autowired
    HttpClientService httpClientService;

    @Override
    public SearchResult getItemListByItemCatId(Long itemCatId, Integer page, Integer rows) {
        String url="http://manage.jt.com/web/itemcat/findItemsByCatId";
        Map<String,String> params = new HashMap<>();
        params.put("itemCatId",itemCatId+"");
        params.put("page",page+"");
        params.put("rows",rows+"");
        String itemJson = httpClientService.doGet(url, params);
        SearchResult result = ObjectMapperUtil.toObject(itemJson, SearchResult.class);
        return result;
    }

    @Override
    public String getItemNameByCatId(Long itemCatId) {
        String url="http://manage.jt.com/web/itemcat/findItemName";
        Map<String,String> params = new HashMap<>();
        params.put("itemCatId",itemCatId+"");
        String itemJson = httpClientService.doGet(url, params);
        return itemJson;
    }
}
